package com.hqu.ms.person;

import com.androidquery.AQuery;
import com.googlecode.androidannotations.annotations.EViewGroup;
import com.googlecode.androidannotations.annotations.ViewById;
import com.hqu.ms.R;
import com.hqu.ms.db.FavDB;
import com.hqu.ms.utils.Constant;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

@EViewGroup(R.layout.ms_fav_item_layout)
public class FavItemVIew extends LinearLayout{

	public FavItemVIew(Context context) {
		super(context);
	}
	
	public FavItemVIew(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	@ViewById
	TextView tvTitle, tvAddress;
	
	@ViewById
	LinearLayout lllayout;
	
	@ViewById
	ImageView ivDelete, ivStore;
	
	
	void bindItem(FavDB fav, boolean showDetele, OnClickListener clickListener){
		if(showDetele){
			ivDelete.setVisibility(View.VISIBLE);
		}else{
			ivDelete.setVisibility(View.GONE);
		}
		if(TextUtils.isEmpty(fav.getMg_picture())){
			ivStore.setVisibility(View.GONE);
			tvTitle.setGravity(Gravity.CENTER);
			lllayout.setGravity(Gravity.CENTER);
		}else{
			ivStore.setVisibility(View.VISIBLE);
			lllayout.setGravity(Gravity.CENTER | Gravity.LEFT);
			tvTitle.setGravity(Gravity.CENTER | Gravity.LEFT);
			AQuery aq = new AQuery(this);
			aq.id(R.id.ivStore).image(Constant.URL_MSGGROUP_SMALL+fav.getMg_picture(), true, true);
		}
		
		tvTitle.setText(fav.getMg_name());
		tvAddress.setText(fav.getMg_address());
		ivDelete.setOnClickListener(clickListener);
		ivDelete.setTag(fav);
		this.setTag(fav);
	}
	
}
